import { getCategory } from '@/api/category'
import { ALL_CATEGORY_ITEM, CATEGORY_NOMAR_DATA } from '@/constants'

const state = () => {
  categorys: CATEGORY_NOMAR_DATA
  currentCategoryIndex: '0'
}
const mutations = {
  setCategorys(state, categorys) {
    state.categorys = [ALL_CATEGORY_ITEM, ...categorys]
  },
  setCategorysCurrentItem(state, currentCategoryIndex) {
    state.currentCategoryIndex = currentCategoryIndex
  }
}
const actions = {
  async requestCategoryData(context) {
    const { categorys } = await getCategory()
    context.commit('setCategorys', categorys)
  }
}

export default {
  // 独立作用域
  namespaced: true,
  state,
  mutations,
  actions
}